unit uNumberFunction;

interface

uses uKalkulesMathDefines;

type

  TNumberFunctionClass = class of TNumberFunction;

  TNumberFunction = class
  private
    FAngleMode: TAngleMode;
  protected
    function FromRadians(AInput: Extended): Extended;
    function ToRadians(AInput: Extended): Extended;
  public
    class function GetName: string; virtual; abstract;

    constructor Create;
    function Evaluate(AInput: Extended): Extended; virtual; abstract;

    property AngleMode: TAngleMode read FAngleMode write FAngleMode;
  end;

implementation

uses Math;

{ TNumberFunction }

constructor TNumberFunction.Create;
begin
  FAngleMode := amDeg;
end;

function TNumberFunction.FromRadians(AInput: Extended): Extended;
begin
  case FAngleMode of
    amDeg:
      Result := RadToDeg(AInput);
    amRad:
      Result := AInput;
    amGrad:
      Result := RadToGrad(AInput);
  end;
end;

function TNumberFunction.ToRadians(AInput: Extended): Extended;
begin
  case FAngleMode of
    amDeg:
      Result := DegToRad(AInput);
    amRad:
      Result := AInput;
    amGrad:
      Result := GradToRad(AInput);
  end;
end;

end.
